From Warren Toomey: make more fields in NMEA optional on read.
authorrobertl <robertl>
Sat, 24 Apr 2010 06:03:17 +0000 (06:03 +0000)
committerrobertl <robertl>
Sat, 24 Apr 2010 06:03:17 +0000 (06:03 +0000)
nmea.c

diff --git a/nmea.c b/nmea.c
index 86f11e20ad42b04986801127ec857602e577d019..2f0276f74f46b32113ddc91f3d7e000b19a5da4e 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -509,22 +509,37 @@ gprmc_parse(char *ibuf)
        double speed,course;
        waypoint *waypt;
        double microseconds;
+       char *dmybuf;
+       int i;
 
        if (trk_head == NULL) {
                trk_head = route_head_alloc();
                track_add_head(trk_head);
        }
 
-       sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf,%u",
+       /*
+        * Read everything except the dmy, in case lngdeg
+        * and lngdir are missing.
+        */
+       sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf",
                &hms, &fix, &latdeg, &latdir,
                &lngdeg, &lngdir,
-               &speed, &course, &dmy);
+               &speed, &course);
 
        if (fix != 'A') {
                /* ignore this fix - it is invalid */
                return;
        }
 
+       /* Skip past nine commas in ibuf to reach the dmy value */
+       for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) {
+               dmybuf= strchr(dmybuf, ',');
+               dmybuf++;
+       }
+
+       /* Now read dmy from the correct position */
+       sscanf(dmybuf,"%u", &dmy);
+
        last_read_time = hms;
        microseconds = MILLI_TO_MICRO(1000 * (hms - (int)hms));